package com.sailing.study.array;

/**[1,2,3,4,5,6,7]
 * target [5,6,7,1,2,3,4]
 * Created by chao.chen on 2019/4/1.
 */
public class RotateArray {


    public Integer[] simpleRotate(Integer[] datas, int from){
        int len = datas.length;
        Integer[] proxy = new Integer[len];
        if (from<0 || from>=len){
            return datas;
        }
        int fromIndex = from - 1;
        int range = len - from + 1;
        for(int i=0; i< range; i++){
            proxy[i] = datas[fromIndex];
            fromIndex++;
        }
        int leftIndex = range ;
        for(int i = 0;leftIndex<len; leftIndex++){
            proxy[leftIndex] = datas[i];
            i++;
        }
        return proxy;
    }



    public static void main(String[] args) {
        Integer[] datas = new Integer[]{1,2,3,4,5,6,7};
        Integer[] rotateResult = new RotateArray().simpleRotate(datas,5);
        System.out.println(Arrays.toString(rotateResult));
    }
}
